home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 2
/
Atari Mega Archive CD - Volume 2.iso
/
minix
/
up1510b.tgz
/
up1510b
/
src
/
commands
/
nroff
/
command.c
next >
Wrap
C/C++ Source or Header
|
1990-07-23
|
17KB
|
1,004 lines
/*
* command.c - command input parser/processor for nroff text processor
*
* adapted for atariST/TOS by Bill Rosenkranz 11/89
* net: rosenkra@hall.cray.com
* CIS: 71460,17
* GENIE: W.ROSENKRANZ
*
* original author:
*
* Stephen L. Browning
* 5723 North Parker Avenue
* Indianapolis, Indiana 46220
*
* history:
*
* - Originally written in BDS C;
* - Adapted for standard C by W. N. Paul
* - Heavily hacked up to conform to "real" nroff by Bill Rosenkranz
*/
#undef NRO_MAIN /* extern globals */
#include <stdio.h>
#include "nroff.h"
/*------------------------------*/
/* comand */
/*------------------------------*/
comand (p)
register char *p;
{
/*
* main command processor
*/
register int i;
register int ct;
register int val;
register int indx;
int newval;
int spval;
char argtyp;
char name[MAXLINE];
char macexp[MXMLEN];
int tmp;
char *pfs;
char fs[20];
/*
* get command code
*/
ct = comtyp (p, macexp);
/*
* error?
*/
if (ct == UNKNOWN)
{
fprintf (err_stream,
"***%s: unrecognized command %s\n", myname, p);
return;
}
/*
* ignore comments
*/
if (ct == COMMENT)
return;
/*
* do escape expansion on command line args
*/
expesc (p, name);
/*
* get value of command
*/
val = getval (p, &argtyp);
/*
* do the command
*/
switch (ct)
{
/* set (¶m, val, type, defval, minval, maxval) */
case FC:
/*
* field delim/pad chars
*
* .fc [delim] [pad]
*/
fprintf (err_stream, "***%s: .fc not available\n", myname);
break;
case TR:
/*
* translate
*
* .tr ab...
*/
fprintf (err_stream, "***%s: .tr not available\n", myname);
break;
case AD:
/*
* adjust
*
* .ad [mode]
*/
p = skipwd (p);
p = skipbl (p);
switch (*p)
{
case 'l':
dc.adjval = ADJ_LEFT;
dc.juval = YES;
break;
case 'r':
dc.adjval = ADJ_RIGHT;
dc.juval = YES;
break;
case 'c':
dc.adjval = ADJ_CENTER;
dc.juval = YES;
break;
case 'b':
case 'n':
dc.adjval = ADJ_BOTH;
dc.juval = YES;
break;
default:
break;
}
break;
case AF:
/*
* assign format to number reg
*
* .af R {1,a,A,i,I,0...1}
*/
p = skipwd (p);
p = skipbl (p);
if (!isalpha (*p))
{
fprintf (err_stream,
"***%s: invalid or missing number register name\n",
myname);
}
else
{
/*
* number register format is 1,a,A,i,I,0...1
* default is 1. for 0001 format, store num dig
* or'ed with 0x80, up to 8 digits.
*/
indx = tolower (*p) - 'a';
p = skipwd (p);
p = skipbl (p);
if (*p == '1')
dc.nrfmt[indx] = '1';
else if (*p == 'a')
dc.nrfmt[indx] = 'a';
else if (*p == 'A')
dc.nrfmt[indx] = 'A';
else if (*p == 'i')
dc.nrfmt[indx] = 'i';
else if (*p == 'I')
dc.nrfmt[indx] = 'I';
else if (*p == '0')
{
for (i = 0; isdigit (p[i]); i++)
;
dc.nrfmt[indx] = (char) (i);
if (dc.nrfmt[indx] <= 0)
dc.nrfmt[indx] = '1';
else if (dc.nrfmt[indx] > 8)
{
dc.nrfmt[indx] = 8;
dc.nrfmt[indx] |= 0x80;
}
else
dc.nrfmt[indx] |= 0x80;
}
else
dc.nrfmt[indx] = '1';
}
break;
case BD:
/*
* embolden font (IGNORED)
*
* .bd [S] F N
*/
break;
case BO:
/*
* bold face
*
* .bo [N]
*/
set (&dc.boval, val, argtyp, 1, 0, HUGE);
dc.cuval = dc.ulval = 0;
break;
case BP:
/*
* begin page
*
* .bp [+/-N]
*/
if (pg.lineno > 0)
space (HUGE);
set (&pg.curpag, val, argtyp, pg.curpag + 1, -HUGE, HUGE);
pg.newpag = pg.curpag;
set_ireg ("%", pg.newpag, 0);
break;
case BR:
/*
* break (page)
*
* .br
*/
robrk ();
break;
case BS:
/*
* backspc in output
*
* .bs [N]
*/
set (&dc.bsflg, val, argtyp, 1, 0, 1);
break;
case C2:
/*
* nobreak char
*
* .c2 [c=']
*/
if (argtyp == '\r' || argtyp == '\n')
dc.nobrchr = '\'';
else
dc.nobrchr = argtyp;
break;
case CC:
/*
* command character
*
* .cc [c=.]
*/
if (argtyp == '\r' || argtyp == '\n')
dc.cmdchr = '.';
else
dc.cmdchr = argtyp;
break;
case CE:
/*
* center
*
* .ce [N]
*/
robrk ();
set (&dc.ceval, val, argtyp, 1, 0, HUGE);
break;
case CS:
/*
* constant space char (IGNORED)
*
* .cs F N M
*/
break;
case CU:
/*
* continuous underline
*
* .cu [N]
*/
set (&dc.cuval, val, argtyp, 1, 0, HUGE);
dc.ulval = dc.boval = 0;
break;
case DE:
/*
* define macro
*
* .de name [end]
*/
ignoring = FALSE;
defmac (p, sofile[dc.flevel]);
break;
case DS:
/*
* define string
*
* .ds name string
*/
defstr (p);
break;
case EC:
/*
* escape char
*
* .ec [c=\]
*/
if (argtyp == '\r' || argtyp == '\n')
dc.escchr = '\\';
else
dc.escchr = argtyp;
dc.escon = YES;
break;
case EF:
/*
* even footer
*
* .ef "a" "b" "c"
*/
gettl (p, pg.efoot, &pg.eflim[0]);
break;
case EH:
/*
* even header
*
* .eh "a" "b" "c"
*/
gettl (p, pg.ehead, &pg.ehlim[0]);
break;
case EN:
/*
* end macro def (should not get one here...)
*
* .en or ..
*/
fprintf (err_stream, "***%s: missing .de command\n", myname);
break;
case EO:
/*
* escape off
*
* .eo
*/
dc.escon = NO;
break;
case FI:
/*
* fill
*
* .fi
*/
robrk ();
dc.fill = YES;
break;
case FL:
/*
* flush NOW
*
* .fl
*/
fflush (out_stream);
break;
case FO:
/*
* footer
*
* .fo "a" "b" "c"
*/
gettl (p, pg.efoot, &pg.eflim[0]);
gettl (p, pg.ofoot, &pg.oflim[0]);
break;
case FT:
/*
* font change
*
* .ft {R,I,B,S,P}
*
* the way it's implemented here, it causes a break
* rather than be environmental...
*/
p = skipwd (p);
p = skipbl (p);
if (!isalpha (*p))
{
fprintf (err_stream,
"***%s: invalid or missing font name\n",
myname);
}
else
{
pfs = &fs[0];
fontchange (*p, pfs);
robrk ();
fflush (out_stream);
fprintf (out_stream, "%s", pfs);
fflush (out_stream);
}
break;
case TL:
case HE:
/*
* header (both are currently identical. .he is -me)
*
* .tl "a" "b" "c"
* .he "a" "b" "c"
*/
gettl (p, pg.ehead, &pg.ehlim[0]);
gettl (p, pg.ohead, &pg.ohlim[0]);
break;
case IG:
/*
* ignore input lines
*
* .ig name
*/
ignoring = TRUE;
defmac (p, sofile[dc.flevel]);
break;
case IN:
/*
* indenting
*
* .in [+/-N]
*/
set (&dc.inval, val, argtyp, 0, 0, dc.rmval - 1);
set_ireg (".i", dc.inval, 0);
dc.tival = dc.inval;
break;
case JU:
/*
* justify
*
* .ju
*/
dc.juval = YES;
break;
case LL:
/*
* line length
*
* .ll [+/-N]
* .rm [+/-N]
*/
set (&dc.rmval, val, argtyp, PAGEWIDTH, dc.tival + 1, HUGE);
set (&dc.llval, val, argtyp, PAGEWIDTH, dc.tival + 1, HUGE);
set_ireg (".l", dc.llval, 0);
break;
case LS:
/*
* line spacing
*
* .ls [+/-N=+1]
*/
set (&dc.lsval, val, argtyp, 1, 1, HUGE);
set_ireg (".v", dc.lsval, 0);
break;
case LT:
/*
* title length
*
* .lt N
*/
set (&dc.ltval, val, argtyp, PAGEWIDTH, 0, HUGE);
pg.ehlim[RIGHT] = dc.ltval;
pg.ohlim[RIGHT] = dc.ltval;
break;
case M1:
/*
* topmost margin
*
* .m1 N
*/
set (&pg.m1val, val, argtyp, 2, 0, HUGE);
break;
case M2:
/*
* second top margin
*
* .m2 N
*/
set (&pg.m2val, val, argtyp, 2, 0, HUGE);
break;
case M3:
/*
* 1st bottom margin
*
* .m3 N
*/
set (&pg.m3val, val, argtyp, 2, 0, HUGE);
pg.bottom = pg.plval - pg.m4val - pg.m3val;
break;
case M4:
/*
* bottom-most marg
*
* .m4 N
*/
set (&pg.m4val, val, argtyp, 2, 0, HUGE);
pg.bottom = pg.plval - pg.m4val - pg.m3val;
break;
case MACRO:
/*
* macro expansion
*
* (internal)
*/
maceval (p, macexp);
break;
case NA:
/*
* no adjust
*
* .na
*/
dc.adjval = ADJ_OFF;
dc.juval = NO;